<?php
/**
 * Created by PhpStorm.
 * 阿里云推送商家app设备id
 * User: caicm
 * Date: 2017/7/29
 * Time: 15:18
 */

namespace WMApi\Model;


use Think\Model;

class WmAliyunPushModel extends Model {

    /**
     * @param int $seller_id
     * @return mixed
     */
    public function find_push_info($seller_id=0){

        $where = array(
            'seller_id' => $seller_id
        );

        return $this->where($where)->find();

    }

    /**
     * @param int $seller_id
     * @param string $android_device_id
     * @param string $ios_device_id
     * @return mixed
     */
    public function add_push($seller_id=0, $android_device_id='', $ios_device_id=''){

        $data = array(
            'seller_id' => $seller_id,
            'android_device_id' => $android_device_id,
            'ios_device_id' => $ios_device_id,
            'add_time' => gmtime(),
        );

        return $this->data($data)->add();

    }

    /**
     * @param int $seller_id
     * @param string $android_device_id
     * @param string $ios_device_id
     * @return bool
     */
    public function update_push($seller_id=0, $android_device_id='', $ios_device_id=''){

        $where = array(
            'seller_id' => $seller_id
        );

        $data = array(
            'android_device_id' => $android_device_id,
            'ios_device_id' => $ios_device_id,
            'update_time' => gmtime(),
        );
        if($android_device_id == '') unset($data['android_device_id']);
        if($ios_device_id == '') unset($data['ios_device_id']);

        return $this->where($where)->data($data)->save();

    }
}